package com.example.yuejian.yuejian.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.base.BaseActivity;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.EditPassword;
import com.example.yuejian.yuejian.model.UserModel;

public class EditPasswordActivity extends BaseActivity {
      private EditText oldPwd;
    private EditText  password;
    private EditText rePwd;
    private ImageView btn_back;
    private Button btn_confirm_edit;
    private ModleListener<EditPassword> listener=new ModleListener<EditPassword>() {
        @Override
        public void onResponse(EditPassword o) {
             EditPassword res=o;
            if (!"0".equals(res.getRetCode()))
            {
                Toast.makeText(EditPasswordActivity.this,res.getRetMsg(),Toast.LENGTH_SHORT).show();
                finish();
            }
            else
            {
                Toast.makeText(EditPasswordActivity.this,res.getRetMsg(),Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(EditPasswordActivity.this,"网络错误",Toast.LENGTH_SHORT).show();
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_password);
        initViews();
        initEvents();
        back();
    }
    private void initViews()
    {
        oldPwd=(EditText)findViewById(R.id.et_editPassword_old_password);
        password=(EditText)findViewById(R.id.et_editPassword_password);
        rePwd=(EditText)findViewById(R.id.et_editPassword_confirm_password);
        btn_confirm_edit=(Button)findViewById(R.id.btn_editPassword_confirm_ok);

    }
    private  void initEvents()
    {
        btn_confirm_edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            UserModel userModel=new UserModel();
            userModel .EditPassword(getUser_id(),oldPwd.getText().toString(),
                    password.getText().toString(),rePwd.getText().toString(),listener);
        }
    });

    }
    private void back()
    {
        btn_back=(ImageView)findViewById(R.id.imgBtn_editPassword_back);
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }
}
